// 封装所有和用户相关的接口函数
import request from '@/utils/http'

// 注册账号
export const createAccountAPI = (data) => {
  return request({
    url: 'account/create',
    method: 'POST',
    data
  })
}

// 校验账号和手机号
export const validateAccountAndPhoneAPI = (account, phone) => {
  return request({
    url: 'account/validate',
    method: 'GET',
    params: {
      account,
      phone
    }
  })
}

// 校验验证码
export const checkCaptchaAPI = (phone, captcha) => {
  return request({
    url: '/account/captcha/check',
    method: 'POST',
    params: {
      phone,
      captcha
    }
  })
}

// 重置密码
export const resetPasswordAPI = (data) => {
  return request({
    url: '/account/password/reset',
    method: 'PUT',
    data
  });
};

// 登录
export const loginAPI = ({ account, password }) => {
  return request({
    url: '/login',
    method: 'POST',
    data: {
      account,
      password
    }
  })
}

// 新增
export const addUserAPI = (data) => {
  return request({
    url: 'admin/user',
    method: 'POST',
    data
  });
};

// 分页查询
export const getUserPageAPI = (params) => {
  return request({
    url: 'admin/user/page',
    method: 'GET',
    params
  });
};

// 删除
export const deleUserAPI = (id) => {
  return request({
    url: 'admin/user',
    method: 'DELETE',
    params: {
      id
    }
  });
};

// 修改
export const editUserAPI = (data) => {
  return request({
    url: 'admin/user',
    method: 'PUT',
    data
  });
};

//用户启用和禁用
export const userByStatusAPI = (status, id) => {
  return request({
    url: `/admin/user/status/${status}`,
    method: 'POST',
    params: {
      id
    }
  })
}

export const getMemberAPI = () => {
  return request({
    url: '/member',
    method: 'GET',
  })
}